#pragma once

template <class TYPE>

class Vector
{
private:
	TYPE*		list;					// the dynamic array of the type
	int			size;					// the current number of elements inside the vector
	int			capacity;				// the number of elements the vector can hold before it needs to allocate more space
	const int	cIncrement;				// the amount to increase the size of the vector by if it runs out of space

public:
	Vector()
	: list(NULL)
	, size(0)
	, capacity(0)
	, cIncrement(10)
{}
	// pushes the argument element into the back of the list
	void push(TYPE toBePushed)
	{
		if(NULL == list)								// the list hasn't been allocated memory yet, then allocate memory
		{
			list = new TYPE[capacity += cIncrement];	// gives 10 elements in memory to start with

			for(int i = 0; i < cIncrement; i++)			// initialize all the elements to NULL
				list[i] = 0;
		}
	
		else if(size == capacity)						// if there's no room, allocate more memory
		{	
			TYPE* biggerList;				// create a temporary list that's bigger than ours
			biggerList = new TYPE[capacity += cIncrement];

		
			for(int i = 0; i < capacity; i++)	// set all values of the bigger list to NULL
				biggerList[i] = 0;
		
		
			for(int i = 0; i < size; i++)		// fill the bigger array with the elements in the old array
			{
				biggerList[i] = list[i];
			}

			delete [] list;						// delete the old array
			list = biggerList;					// set the list to point at the bigger list
		}


		list[size++] = toBePushed;				// add the object to the next spot in the list, then increment size
	}

	// removes the indexed item from the vector
	void remove(int index)
	{
		for(int i = index; i < size-1; i++)
		{
			list[i] = list[i+1];		// starting from the desired index to remove, moves all other pieces after it back by one
		}
		size--;
	}

	// returns the last element of the list, deleting it from the list
	TYPE pop()							
	{
		TYPE temp;			//  create a temporary T to hold the element to be popped
		temp = list[size--];	// grab the last element and store it in temp, then decrement size
		list[size] = NULL;		// delete that element from the list

		return temp;			// return the popped value
	}
	// returns the indexed element
	TYPE operator[](int index)			
	{
		return list[index];
	}
	// returns the number of elements in the list
	int sizeOf() { return size; }		
	// deletes each element in the list, replacing it with NULL
	void clear()						
	{	
		//for(int i = 0 ; i < capacity; i++)	// set element values to NULL
		//	list[i] = NULL;	

		release();
	}
	// deallocates memory if necessary
	void release()
	{
		if(NULL != list)
		{
			delete [] list;
			list = NULL;
			size = 0;
			capacity = 0;
		}
	}
};




